﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace WorkLogger.Client {
	[Serializable]
	public class AppOptions {
		public static string FileName { get; set; }

		/// <summary>
		/// Путь до папки с программой.
		/// </summary>
		public static string ProgramPath { get; set; }

		/// <summary>
		/// Учитываемый перерыв (кофебрейк).
		/// </summary>
		public int CoffeeBreak { get; set; }

		/// <summary>
		/// Оклад за час.
		/// </summary>
		public decimal Salary { get; set; }

		/// <summary>
		/// Вычитать НДФЛ.
		/// </summary>
		public bool DeductIncomeTax { get; set; }

		private TimeSpanXml workDayDuration;

		/// <summary>
		/// Продолжительность рабочего дня.
		/// </summary>
		public TimeSpanXml WorkDayDuration {
			get { return workDayDuration ?? (workDayDuration = new TimeSpanXml()); }
			set { workDayDuration = value; }
		}

		public static void Save(AppOptions options) {
			var serializer = new XmlSerializer(options.GetType());
			using (var stream = new StreamWriter(FileName, false)) {
				serializer.Serialize(stream, options);
			}
		}

		public static AppOptions Load() {
			var serializer = new XmlSerializer(typeof(AppOptions));
			using (var stream = new StreamReader(FileName, false)) {
				return (AppOptions)serializer.Deserialize(stream);
			}
		}
	}
}